<table class="table table-hover">
    <thead>
        <tr>
            @if(\Encore\Admin\Facades\Admin::user()->can('os-in.os.receive-ex-in') || \Encore\Admin\Facades\Admin::user()->can('os-in.os.receive-ex-pay'))
            <th></th>
            @endif
            <th>发货单号</th>
            <th>批次号</th>
            <th>FNSKU</th>
            <th>SKU</th>
            <th>SKU名称</th>
            <th>品类</th>
            <th>箱号</th>
            <th>箱数</th>
            <th>本次入库箱数</th>
            <th>已入库箱数</th>
            <th>未入库箱数</th>
            <th>单箱数量</th>
            <th>目的仓库</th>
            <th>账号</th>
            <th>站点</th>
            <th>状态</th>
            <th>异常处理</th>
            <th>操作</th>
        </tr>
    </thead>
    <tbody>
    @php
        $boxNo = [];
    @endphp
        @foreach($paginator as $row)
            @php
                if(!array_key_exists($row->delivery_no.'_'.$row->box_no,$boxNo)){
                    $boxNo[$row->delivery_no.'_'.$row->box_no] = 1;
                }else{
                    $boxNo[$row->delivery_no.'_'.$row->box_no] += 1;
                }
            @endphp
            <tr>
                @if($boxNo[$row->delivery_no.'_'.$row->box_no] == 1)
                    @if(\Encore\Admin\Facades\Admin::user()->can('os-in.os.receive-ex-in') || \Encore\Admin\Facades\Admin::user()->can('os-in.os.receive-ex-pay'))
                        @if($row->status != 3 && $row->ex_deal == 1)
                            <td><input type="checkbox" class="grid-row-checkbox" data-id="{{ $row->id }}" /></td>
                        @else
                            <td></td>
                        @endif
                    @endif
                    <td>{{ $row->delivery_no }}</td>
                    <td>{{ $row->batch_no }}</td>
                @else
                    @if(\Encore\Admin\Facades\Admin::user()->can('os-in.os.receive-ex-in') || \Encore\Admin\Facades\Admin::user()->can('os-in.os.receive-ex-pay'))
                        <td></td>
                    @endif
                    <td></td>
                    <td></td>
                @endif
                    <td>{{ $row->fnsku }}</td>
                    <td>{{ $row->sku->psku_code ?? '' }}</td>
                    <td>{{ $row->sku->psku_cn ?? '' }}</td>
                    <td>{{ $row->skuClassify->title ?? '' }}</td>
                @if($boxNo[$row->delivery_no.'_'.$row->box_no] == 1)
                    <td>{{ $row->box_no }}</td>
                    <td>{{ $row->total }}</td>
                    @if(\Encore\Admin\Facades\Admin::user()->can('os-in.os.receive-ex-in') || \Encore\Admin\Facades\Admin::user()->can('os-in.os.receive-ex-pay'))
                        @if($row->status != 3 && $row->ex_deal == 1)
                            <td>
                                <input type="hidden" name="detail_key" value="{{ $row->delivery_no.'_'.$row->box_no }}">
                                <input type="hidden" name="batch_no" value="{{ $row->batch_no }}">
                                <input type="hidden" name="box_no" value="{{ $row->box_no }}">
                                <input type="text" class="this_storage_num_"
                                       style="width: 100px; text-align: right;"
                                       name="this_storage_num"
                                       data-value="{{ max(($row->total ?? 0) - ($row->storage_total ?? 0),0) }}"
                                       value="{{ max(($row->total ?? 0) - ($row->storage_total ?? 0),0) }}">
                            </td>
                        @else
                            <td></td>
                        @endif
                    @else
                        <td></td>
                    @endif
                    <td>{{ $row->storage_total }}</td>
                    <td>{{ $row->total - $row->storage_total }}</td>
                @else
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                @endif
                <td>{{ $row->num_per_box }}</td>
                <td>{{ $row->warehouse->w_code ?? '' }}</td>
                <td>{{ \App\Models\Basics\SysPlatAccount::getAccountById($row->account_id) }}</td>
                <td>{{ $row->area->area ?? '' }}</td>
                <td>{{ \App\Models\OverSeasIn\DeliveryBox::$_status[$row->status] }}</td>
                <td>{{ \App\Models\OverSeasIn\DeliveryBox::$_esDeal[$row->ex_deal] }}</td>
                <td>
                    <a href="/xqc/overseas-in/dropshipping-receive-ex/{{ $row->delivery_no }}" class="btn btn-xs btn-primary">查看</a>
                </td>
            </tr>
        @endforeach
    </tbody>
</table>
<script language="JavaScript" type="text/javascript">
    $(function () {
        $('.grid-row-checkbox').iCheck({checkboxClass:'icheckbox_minimal-blue'}).on('ifChanged', function () {
            if (this.checked) {
                $(this).closest('tr').css('background-color', '#ffffd5');
            } else {
                $(this).closest('tr').css('background-color', '');
            }
        });

        $(".this_storage_num_").inputmask("integer",
            {
                onKeyValidation: function () {
                    var v = $(this).data('value');
                    var thisV = $(this).val();
                    if(thisV < 0 || thisV > v){
                        $(this).val(v);
                    }
                }
            }
        );
    });
</script>
